Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
@types/ssh2
Advanced tools
@types/ssh2 provides TypeScript definitions for the ssh2 library, which is a client and server implementation of the SSH2 protocol. This package allows developers to use the ssh2 library with TypeScript, providing type safety and autocompletion features.
Establishing an SSH Connection
This code sample demonstrates how to establish an SSH connection to a remote server and execute a command ('uptime') on that server. The connection is established using the ssh2 library, and the TypeScript definitions provided by @types/ssh2 ensure type safety.
const Client = require('ssh2').Client;
const conn = new Client();
conn.on('ready', () => {
console.log('Client :: ready');
conn.exec('uptime', (err, stream) => {
if (err) throw err;
stream.on('close', (code, signal) => {
console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
conn.end();
}).on('data', (data) => {
console.log('STDOUT: ' + data);
}).stderr.on('data', (data) => {
console.log('STDERR: ' + data);
});
});
}).connect({
host: '127.0.0.1',
port: 22,
username: 'frylock',
privateKey: require('fs').readFileSync('/here/is/my/key')
});
Setting up an SSH Server
This code sample demonstrates how to set up an SSH server that listens for incoming connections. The server authenticates clients using a username and password, and allows them to execute commands. The TypeScript definitions provided by @types/ssh2 ensure type safety for the ssh2 library's server functionality.
const { Server } = require('ssh2');
const fs = require('fs');
const server = new Server({
hostKeys: [fs.readFileSync('host.key')]
}, (client) => {
console.log('Client connected!');
client.on('authentication', (ctx) => {
if (ctx.method === 'password' && ctx.username === 'foo' && ctx.password === 'bar')
ctx.accept();
else
ctx.reject();
}).on('ready', () => {
console.log('Client authenticated!');
client.on('session', (accept, reject) => {
const session = accept();
session.on('exec', (accept, reject, info) => {
console.log('Client wants to execute: ' + info.command);
const stream = accept();
stream.stderr.write('Oh no, the dreaded errors!
');
stream.write('Just kidding about the errors!
');
stream.exit(0);
stream.end();
});
});
}).on('end', () => {
console.log('Client disconnected');
});
}).listen(22, '127.0.0.1', () => {
console.log('Listening on port 22');
});
node-ssh is a simpler, higher-level library for SSH connections in Node.js. It provides a more user-friendly API compared to ssh2, but may lack some of the advanced features and flexibility of ssh2.
ssh2-promise is a wrapper around ssh2 that provides a promise-based API. This can make it easier to work with asynchronous operations compared to the callback-based API of ssh2.
simple-ssh is another high-level library for SSH connections in Node.js. It focuses on simplicity and ease of use, but may not offer the same level of control and customization as ssh2.
npm install --save @types/ssh2
This package contains type definitions for ssh2 (https://github.com/mscdex/ssh2).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/ssh2.
These definitions were written by Qubo, Ron Buckton, Will Boyce, Lucas Motta, Tom Xu, Leo Toneff, and Lucian Buzzo.
FAQs
TypeScript definitions for ssh2
The npm package @types/ssh2 receives a total of 628,614 weekly downloads. As such, @types/ssh2 popularity was classified as popular.
We found that @types/ssh2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.